package com.cn.kabalifeuser.ui.my.activity;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.my.bean.HelpDetailsBean;
import com.cn.kabalifeuser.ui.my.bean.HelpListBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/10.
 * function:
 */
public class HelpListActivityPresenter extends BasePresenter<HelpListActivityView> {

    public void onHelpListData(String token, int page, int limit) {
        OkGo.<HelpListBean>get(Api.API_USER_HELP_LIST)
                .headers("token", token)
                .params("page", page)
                .params("limit", limit)
                .execute(new CacheCallBack<HelpListBean>() {
                    @Override
                    public void onSuccess(Response<HelpListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("帮助：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onHelpListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }


    public void onHelpDetailsData(String token, int id) {
        OkGo.<HelpDetailsBean>get(Api.API_USER_HELP)
                .headers("token", token)
                .params("id", id)
                .execute(new CacheCallBack<HelpDetailsBean>() {
                    @Override
                    public void onSuccess(Response<HelpDetailsBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("帮助：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onHelpDetailsSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
